﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Content.Master" Inherits="System.Web.Mvc.ViewPage<MethodWorx.CMS.UI.Areas.Application.Models.CreatePageModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">


<script language="javascript">

var constraints = new Array();
<%if(this.Model.Request.ParentPage != null){ %>
<%foreach(var i in this.Model.Request.ParentPage.Template.PageTemplateConstraints) {%>
    constraints.push({ id: "<%=i.RelatedTemplate.Id %>", mr: '<%= i.MinimumRequired%>', ma: '<%=i.MaximumAllowed %>' });
      <%} %>    
<%} %>

    $(document).ready(function () {
        $("#Request_ExistingPageTemplate").change(function () {
            if ($(this).val() == "") {
                $("#Request_NewTemplateName").removeAttr("disabled");
                $("#parentTemplatePanel").show();
                $("#Request_MinimumRequired").val("");
                $("#Request_MaximumAllowed").val("");
            }
            else {
                $("#Request_NewTemplateName").attr("disabled", "disabled");
                $("#parentTemplatePanel").hide();
                $("#Request_MinimumRequired").val("");
                $("#Request_MaximumAllowed").val("");
                var me = this;
                $(constraints).each(function(c, i)
                {
                    if(this.id == $(me).val())
                    {
                        $("#Request_MinimumRequired").val(this.ma);
                        $("#Request_MaximumAllowed").val(this.mr);
                    }
                });
            }
        });
    });
</script>
<script language="javascript">
    $(document).ready(function () { $("#cancel").click(function () { window.parent.closeDialog(); }) });
    </script>
<%using(Html.BeginForm()) { %>
<%if (this.Model.Request.ParentPage != null)
  { %>
<div class="formItem">
    <label>Parent Page:</label> <%=this.Model.Request.ParentPage.Name%> (<%=this.Model.Request.ParentPage.Template.Name%>)
</div>
<%} %>
<div class="formItem">
    <label>Existing Template:</label>
    <%=Html.DropDownListFor(m => m.Request.ExistingPageTemplate, this.Model.GetPageTemplateSelectList(), "[New Template]") %><br />
    <%=Html.ValidationMessageFor(m => m.Request.ExistingPageTemplate)%>
</div>
<div class="formItem">
    <label>New Template:</label>
    <%=Html.TextBoxFor(m => m.Request.NewTemplateName) %><br />
    <%=Html.ValidationMessageFor(m => m.Request.NewTemplateName)%>
</div>
<div class="formItem" id="parentTemplatePanel">
    <label>Parent Template:</label>
    <%=Html.DropDownListFor(m => m.Request.ParentTemplate, this.Model.GetParentTemplateSelectList(), "-- Please Select --") %><br />
    <%=Html.ValidationMessageFor(m => m.Request.NewTemplateName)%>
</div>
<%if (this.Model.Request.ParentPage != null)
  { %>
<div class="formItem">
    <em>Please enter how many times this template can published under the template: <%=this.Model.Request.ParentPage.Name%> </em>
</div>
<div class="formItem">
    <label>Minimum Required:</label>
    <%=Html.TextBoxFor(m => m.Request.MinimumRequired)%><br />
    <%=Html.ValidationMessageFor(m => m.Request.MinimumRequired)%>
</div>
<div class="formItem">
    <label>Maximum Allowed:</label>
    <%=Html.TextBoxFor(m => m.Request.MaximumAllowed)%><br />
    <%=Html.ValidationMessageFor(m => m.Request.MaximumAllowed)%>
</div>
<%} %>
<div class="formItem">
    <button>Next >></button>
    <button type="button" id="cancel">Cancel</button>
</div>
<%} %>
</asp:Content>
